package main

import (
	"fmt"
	"os"
	"strings"
	"xiaowu/pkg/core"
)

const fp = "./fulltest.csv"

func main() {
	if bytes, err := os.ReadFile(fp); nil != err {
		panic(err.Error())
	} else {
		lines := strings.Split(string(bytes), "\n")
		head, body := lines[0], lines[1:]
		for idx, old := range body {
			s := strings.Split(old, ",")
			for len(s) < 4 {
				s = append(s, "")
			}
			if s[0] != "" {
				translated, comment, debug, err := core.Translate(s[0])
				s[2] = translated
				s[3] = ""
				if s[2] != s[1] {
					s[3] = "YES"
					fmt.Printf("%s,%s,%s,%+v,%+v,%s\n", s[0], s[1], s[2], comment, debug, err)
				}

				body[idx] = strings.Join(s, ",")
			}
		}

		lines = append([]string{head}, body...)
		bytes = []byte(strings.Join(lines, "\n"))
		os.WriteFile(fp, bytes, 0644)
	}
}
